home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / flowObjects.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.9 KB  |  218 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Dec. 4/96
  22. //  Author:         clm
  23. //
  24. //  Procedure Name:
  25. //      flowObjects
  26. //
  27. //  Description:
  28. //        Flows the objects on the selection list with the given
  29. //        command flags
  30. //
  31. //  Return Value:
  32. //      int - number of objects flowed
  33. //
  34.  
  35.  
  36. //        Given the object, we first check to see if this object is already
  37. //        animated by motion path animation with Follow On. It's a crude check:
  38. //        we look to see if the 'rotate', 'rx', 'ry' or 'rz' attributes are
  39. //        connected to a motion path node - if any of them are, then the object
  40. //        is animated by a motion path, and the fact that
  41. //        the rotate attribute is connected means that Follow is On.
  42. //        If this is not true, we don't do the flow. The 'flow' command will do
  43. //        more stringent checking.
  44. //
  45. //        Once we have found the motion path node, we look to see which of the
  46. //        X, Y and Z local axes of the object is being used for the "Front" and
  47. //        "Up" of the motion. Then we map the flowDivisions[Front,Up,Side]
  48. //        accordingly to the X, Y and Z divisions for the flow command.
  49. global proc int flowObject(string $object,
  50.                     int $front, int $up, int $side,
  51.                     int $aroundObject, int $localEffect,
  52.                     int $localFront, int $localUp, int $localSide)
  53. {
  54.     string $result[];
  55.     string $resultX[];
  56.     string $resultY[];
  57.     string $resultZ[];
  58.  
  59.     // We're putting a 'catch' in here just in case the $object
  60.     // does not have a "rotate" attribute and the 'listConnections'
  61.     // would fail, so that we can exit gracefully.
  62.     //
  63.     if(catch ($result  = `listConnections ($object+".rotate")`)) {
  64.         return 0;
  65.     }
  66.     if(catch ($resultX = `listConnections ($object+".rotateX")`)) {
  67.         return 0;
  68.     }
  69.     if(catch ($resultY = `listConnections ($object+".rotateY")`)) {
  70.         return 0;
  71.     }
  72.     if(catch ($resultZ = `listConnections ($object+".rotateZ")`))
  73.     {
  74.         return 0;
  75.     }
  76.  
  77.     // Not animated by a motion path with follow
  78.     //
  79.     string $node;
  80.     switch(0) {
  81.     default:
  82.         if( size($result) != 0 ) {
  83.             $node = $result[0];
  84.             $result = `ls -showType $node`;
  85.             if ("motionPath" == $result[1])        break; 
  86.         }
  87.         // no motionPath node connected to the rotate attr
  88.  
  89.         if( size($resultX) != 0 ) {
  90.             $node = $resultX[0];
  91.             $result = `ls -showType $node`;
  92.             if ("motionPath" == $result[1])    break;
  93.         }
  94.         // no motionPath node connected to the rotateX attr
  95.  
  96.         if( size($resultY) != 0 ) {
  97.             $node = $resultY[0];
  98.             $result = `ls -showType $node`;
  99.             if ("motionPath" == $result[1])    break;
  100.         }
  101.         // no motionPath node connected to the rotateY attr
  102.  
  103.         if( size($resultZ) != 0 ) {
  104.             $node = $resultZ[0];
  105.             $result = `ls -showType $node`;
  106.             if ("motionPath" == $result[1])        break;
  107.         }
  108.         // no motionPath node connected to the rotateZ attr
  109.  
  110.         return 0;
  111.         break;
  112.     }
  113.  
  114.     // Now that we have the motion path node, determine which of the
  115.     // X, Y and Z are being used for the Front, Up and Side
  116.     //
  117.     int $frontAxis = `getAttr ($node+".frontAxis")`;
  118.     int $upAxis = `getAttr ($node+".upAxis")`;
  119.     int $Xdiv, $Ydiv, $Zdiv;
  120.     int $Xeffect, $Yeffect, $Zeffect;
  121.  
  122.     switch ($frontAxis)
  123.     {
  124.         case 0:    // Front axis is X
  125.             $Xdiv = $front;
  126.             $Xeffect = $localFront;
  127.             if ($upAxis == 1)
  128.             {
  129.                 $Ydiv = $up;
  130.                 $Yeffect = $localUp;
  131.                 $Zdiv = $side;
  132.                 $Zeffect = $localSide;
  133.             }
  134.             else    // $upAxis is 2
  135.             {
  136.                 $Zdiv = $up;
  137.                 $Zeffect = $localUp;
  138.                 $Ydiv = $side;
  139.                 $Yeffect = $localSide;
  140.             }
  141.             break;
  142.         case 1: // Front axis is Y
  143.             $Ydiv = $front;
  144.             $Yeffect = $localFront;
  145.             if ($upAxis == 0)
  146.             {
  147.                 $Xdiv = $up;
  148.                 $Xeffect = $localUp;
  149.                 $Zdiv = $side;
  150.                 $Zeffect = $localSide;
  151.             }
  152.             else    // $up is 2
  153.             {
  154.                 $Zdiv = $up;
  155.                 $Zeffect = $localUp;
  156.                 $Xdiv = $side;
  157.                 $Xeffect = $localSide;
  158.             }
  159.             break;
  160.         case 2: // Front axis is Z
  161.         default:
  162.             $Zdiv = $front;
  163.             $Zeffect = $localFront;
  164.             if ($upAxis == 0)
  165.             {
  166.                 $Xdiv = $up;
  167.                 $Xeffect = $localUp;
  168.                 $Ydiv = $side;
  169.                 $Yeffect = $localSide;
  170.             }
  171.             else    // $up is 1
  172.             {
  173.                 $Ydiv = $up;
  174.                 $Yeffect = $localUp;
  175.                 $Xdiv = $side;
  176.                 $Xeffect = $localSide;
  177.             }
  178.             break;
  179.     }
  180.  
  181.     evalEcho("flow -divisions "+$Xdiv+" "+$Ydiv+" "+$Zdiv+
  182.          " -objectCentered "+$aroundObject+
  183.          " -localCompute "+$localEffect+
  184.          " -localDivisions "+$Xeffect+" "+$Yeffect+" "+$Zeffect+" "+
  185.          $object);
  186.  
  187.     return 1;
  188. }
  189.  
  190. global proc int flowObjects(int $front, int $up, int $side,
  191.                             int $aroundObject, int $localEffect,
  192.                             int $localFront, int $localUp, int $localSide)
  193. {
  194.     // For each object on the selection list, verify that it is
  195.     // animated with a motion path with Follow on, and then do
  196.     // the flow for that object.
  197.     //
  198.     int $processed = 0;
  199.     string $result[] = `ls -sl -showType`;
  200.  
  201.     for ($i = 0; $i < size($result); $i += 2)
  202.     {
  203.         if ($result[$i+1] == "transform")
  204.         {
  205.             $processed +=
  206.                 flowObject($result[$i], $front, $up, $side, $aroundObject,
  207.                            $localEffect, $localFront, $localUp, $localSide);
  208.         }
  209.     }
  210.  
  211.     if ($processed == 0)
  212.     {
  213.         warning("None of the selected objects are animated by a motion path with the Follow option");
  214.     }
  215.  
  216.     return $processed;
  217. }
  218.